﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Drink
{

    //抽象出的一个父类角色  
    public abstract class Drink
    {
        public abstract string DrinkShow();
    }

    //具体角色  
    class 美年达 : Drink
    {
        //获取一瓶美年达  
        public override string DrinkShow()
        {
            return "你选择的是美年达";
        }
    }
    class 雪碧 : Drink
    {
        //获取一瓶雪碧  
        public override string DrinkShow()
        {
            return "您选择的是雪碧";
        }
    }
    class 可口可乐 : Drink
    {
        //获取一瓶可口可乐  
        public override string DrinkShow()
        {
            return "您选择的是可口可乐";
        }
    }

    //现在建立一个自动售货机工厂类  
    public class DrinkFactory
    {
        public static Drink createDrink(string type)
        {
            Drink dri = null;
            switch (type)
            {
                case "美年达":
                    dri = new 美年达();
                    break;
                case "雪碧":
                    dri = new 雪碧();
                    break;
                case "可口可乐":
                    dri = new 可口可乐();
                    break;
            }
            return dri;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                //实例化各种饮料  
                Drink 美年达 = DrinkFactory.createDrink("美年达");
                Drink 雪碧 = DrinkFactory.createDrink("雪碧");
                Drink 可口可乐 = DrinkFactory.createDrink("可口可乐");
                //获取饮料  
                if (美年达 != null)
                {
                    Console.WriteLine(美年达.DrinkShow());
                }
                if (雪碧 != null)
                {
                    Console.WriteLine(雪碧.DrinkShow());
                }
                if (可口可乐 != null)
                {
                    Console.WriteLine(可口可乐.DrinkShow());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("您输入有错：" + ex.Message);
            }
        }
    }
}
